EVENT_RULES = {
    "aggs": {
        "filter": [
            {'term': {'bet_order_user_type': 0}},
        ],
        "groups": [
            {
                "group_name": "玩法/子玩法",
                "field_id": "bet_order_sub_type",
                "is_keyword": True,
                "field_name": "玩法",
                "sub_fields": [
                    {
                        "field_id": "bet_order_third_type",
                        "is_keyword": True,
                        "field_name": "子玩法"
                    },
                ]
            },
            {
                "group_name": "渠道",
                "field_id": "_chn",
                "is_keyword": True,
                "field_name": "渠道"
            }
        ],
        "values": [
            {
                "value_id": "bet_order_bet_amount",
                "value_name": "投注",
                "fmt": "\"%.2f\" % a"
            },
            {
                "value_id": "bet_order_award_amount",
                "value_name": "中奖",
                "fmt": "\"%.2f\" % a"
            },
            {
                "value_id": "bet_order_tax_amount",
                "value_name": "税收",
                "fmt": "\"%.2f\" % a"
            },
            {
                "value_id": "bet_order_profit",
                "value_name": "利润",
                "value_expr": "bet_order_bet_amount - bet_order_award_amount",
                "fmt": "\"%.2f\" % v"
            },
            {
                "value_id": "bet_order_profit_rate",
                "value_name": "利润率",
                "value_expr": ("(bet_order_bet_amount - bet_order_award_amount)/"
                               "(bet_order_bet_amount)"),
                "fmt": "\"%.2f\" % (v * 100)"
            }
        ],
        "uv": {
            "field_id": "_user_id",
            "field_name": "参与人次"
        },
        "pv": {
            "field_name": "参与次数"
        }
    }
}

EVENT_CONFIG = {
    "event_id": "bet_order",
    "event_name": "投注订单",
    "values": {
        "_user_id": {
            "field_name": "用戶ID",
            "value_type": "long",
        },
        "user_type": {
            "field_name": "用户类型 真实用户: 0 机器人: 1",
            "value_type": "long",
        },
        "sub_type": {
            "field_name": "玩法种类",
            "value_type": "string"
        },
        "third_type": {
            "field_name": "房间号",
            "value_type": "string",
            "required": False
        },
        "limit": {
            "field_name": "门槛",
            "value_type": "string",
            "required": False
        },
        "out_trans_id": {
            "field_name": "订单号",
            "value_type": "string",
            "required": False
        },
        "seq_no": {
            "field_name": "期号",
            "value_type": "string",
            "required": False,
        },
        "bet_amount": {
            "field_name": "订单金额",
            "value_type": "float",
            "required": False,
        },
        "award_amount": {
            "field_name": "中奖金额",
            "value_type": "float",
        },
        "tax_amount": {
            "field_name": "税收",
            "value_type": "float",
        },
    },
    "rule": EVENT_RULES
}
